import requests

# 爬取多张网页
for i in range(1,6):
    url = f"https://news.ncu.edu.cn/ndyw/index{i}.htm"
    response = requests.get(url)
    response.encoding = response.apparent_encoding  # 自动识别编码

    if response.status_code == 200:
        with open(f"web/index{i}.htm", "w", encoding=response.encoding) as f:
            f.write(response.text)
        print(f"页面已保存为 index{i}.htm")
    else:
        print(f"请求失败，状态码: {response.status_code}")